<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/4/28
 * Time: 10:08
 */
namespace app\admin\controller;
use think\Db;
use think\Request;
class Mobile extends Base {

    public function index(){
        if(Request::instance()->isAjax()){
            //安卓
            $man = Db::table('up_u_user')
                ->field('user_mobile, count(user_id) as value')
                ->where('user_mobile' , 1)
                ->find();

            //IOS
            $woman = Db::table('up_u_user')
                ->field('user_mobile, count(user_id) as value')
                ->where('user_mobile', 2)
                ->find();
            $man['name'] = 'Android';
            $woman['name'] = 'IPhone';

            unset($man['user_mobile']);
            unset($woman['user_mobile']);
            $list = [];
            array_push($list, $man);
            array_push($list, $woman);

            return json(['sex' => $list]);
        }
        return $this->fetch();
    }
    public function coupon(){
        $all = Db::table('up_shop_coupon')
            ->sum('coupon_num');
        //领取的
        $all_get = Db::table('up_shop_coupon')
            ->sum('coupon_get_num');
        //未领取的
        $all_not_get = $all - $all_get;

        //已核销的
        $all_use = Db::table('up_shop_coupon')
            ->sum('coupon_use_num');
        //未核销的
        $all_not_use = $all_get - $all_use;
        $data = [
            'all_get' => $all_get,
            'all_not_get' => $all_not_get,

            'all_use' => $all_use,
            'all_not_use' => $all_not_use,
        ];
        $this->assign('data',$data);
        return $this->fetch();
    }
}